import { Component, OnInit } from '@angular/core';
import { MessageService } from './../core/message.service';
import { ApiService } from '../core/api';
import { Router, ActivatedRoute } from '@angular/router';
import { DialogService, ToptipsService } from 'ngx-weui';
import { I18nService } from '../core/i18n/i18n.service';
import { StorageService } from '../core/sotrage/storage.service';

@Component({
	templateUrl: './userCenter.html',
	styleUrls: ['./userCenter.less'],
})
export class UserCenterComponent implements OnInit {
	balance;
	res: any = {};
	userDel: any = { userWalletForUserView: [] };
	active = 1;
	pageNo = 1;
	show = false;
	showAmount = false;
	payList = [];
	loading1 = true;
	loading2 = true;
	dialogShow = false;
	iData;
	walletBalancePageData = { pageNo: 1 };
	walletBalances = [];
	constructor(
		private sto: StorageService,
		private i: I18nService,
		private api: ApiService,
		private message: MessageService,
		private router: Router,
		private activeRouter: ActivatedRoute,
		private srv: DialogService,
		private toptips: ToptipsService
	) {
		this.message.sendMessage('my');
		this.i.get([
			'MSG.sfqxdd',
			'MSG.ddqxcg',
		]).subscribe(res => {
			this.iData = res;
		});
	}

	ngOnInit() {
		this.userDel = this.sto.get('user');
		this.userDel ? this.getBalance() : this.router.navigate(['/login']);
	}

	getBalance() {
		this.api.post('获取余额', {}).then(res => {
			this.balance = res['data']['availableBalance'];
		});
		this.api.post('用户各游戏内钱包余额列表', this.walletBalancePageData).then(res => {
			this.walletBalances = res['data']['list'];
		});
	}
	onOutsize(bool) {
		this.dialogShow = bool;
	}
	chickOut() {
		this.dialogShow = false;
		this.sto.remove('user');
		localStorage.removeItem('token');
		localStorage.removeItem('gameToken');
		this.router.navigate(['/login']);
	}

	toggleAmount() {
		this.showAmount = !this.showAmount;
	}

	onLHCZ() {
		this.router.navigate(['/investBalance'], {
			queryParams: {
				// travelOrderId: item.id,
			},
		});
	}
	cancel(item) {
		this.dialogShow = false;
	}
}
